#include<iostream>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<stack>
#include<cmath>
#include<string>
#include<unordered_set>
#include<map>
using namespace std;

unordered_map<int, vector<int>> ma;
vector<int> arr(1, 0);

int dfs(int pos, int pre, int num, int m)
{
    if (arr[pos]) num += 1;
    else num = 0;
    if (num > m) return 0;
    int ans = 0;
    int flag = 1;
    for (auto& x : ma[pos])
    {
        if (x == pre) continue;
        flag = 0;
        ans += dfs(x, pos, num, m);
    }
    return ans + flag;
}

void solve()
{
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int temp; cin >> temp;
        arr.push_back(temp);
    }
    for (int i = 1; i < n; i++)
    {
        int a, b; cin >> a >> b;
        ma[a].push_back(b);
        ma[b].push_back(a);
    }
    cout << dfs(1, -1, 0, m) << endl;
}

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    solve();
    return 0;
}